import axios from '@/libs/api.request'

const ENTITY = '/api/news'
const list = data => {
  return axios.request({
    url: `${ENTITY}`,
    params: data,
    method: 'get'
  })
}
const create = data => {
  return axios.request({
    url: `${ENTITY}`,
    data,
    method: 'post'
  })
}
const update = data => {
  return axios.request({
    url: `${ENTITY}/${data._id}`,
    data,
    method: 'put'
  })
}
const remove = ids => {
  if (typeof ids === 'string') {
    ids = [ids]
  }
  return axios.request({
    url: `${ENTITY}/${ids[0]}`,
    data: { ids },
    method: 'delete'
  })
}
const uploadImg = data => {
  return axios.request({
    url: `/api/uploadimg`,
    data,
    method: 'post'
  })
}

export default {
  list,
  create,
  update,
  remove,
  uploadImg
}
